<script>
    var SKUResult = {};
    var skuquantity = '<?php echo $allcount; ?>';
    var data = <?php echo $skuprice; ?>;
    var quantity = '<?php echo $allcount; ?>';
    var oldprice = '<?php
echo number_format($product['maxOrMinMarketPrice']['0'],2);
if ($product['maxOrMinMarketPrice']['1']) {
    echo ' - ' . number_format($product['maxOrMinMarketPrice']['1'],2);
}
?>';
    initSKU(); //初始化sku价格遍历.
//    alert(SKUResult['5,7']['prices']['skuPrice']);
</script>
<?php
   // var_dump($product);
?>
<div class="wp tm20 cl">
    <div class="area970 z">
        <h2 class="restaurant_name">商家：<a href="<?php echo $this->createUrl('search/index', array('k' => urlencode($product['restaurantName']))); ?>"><?php echo $product['restaurantName'];?></a></h2>
        <div class="foodviewout cl">
            <div class="viewimtout rel z">
                <div class="focusimg">
                    <ul class="fimglist cl">
                        <?php for ($p = 0; $p < count($product['productImg']); $p++) { ?>
                            <li><a href="javascript:void(0);"><img src="<?php echo $product['productImg'][$p]; ?>"/></a></li>
                        <?php } ?>
                    </ul>
                </div> 
                <div class="focustool">
                    <ul class="ftoollist cl">
                        <?php for ($p = 0; $p < count($product['productImg']); $p++) { ?>
                            <li<?php if ($p == 0) { ?> class="on"<?php } ?>><a href="javascript:void(0);"><img src="<?php echo $product['productImg'][$p]; ?>"/></a></li>
                        <?php } ?>
                    </ul>
                </div>
            </div>
            <div class="y foodview_info">
                <h2><?php echo $product['name']; ?></h2>
                <div class="tags cl"><span class="cmicons z"></span>
                    <?php for ($i = 0; $i < count($keywords); $i++) { ?><a href="<?php echo $this->createUrl('search/index', array('k' => urlencode($keywords[$i]))); ?>"><?php echo $keywords[$i]; ?></a><?php } ?></div>
                <div class="foodview_price tm10 cl">
                    <em class="z">促销价</em>
                    <div class="ml"><b>￥<span id="skuprice"><?php echo number_format($product['maxOrMinMarketPrice']['0'],2); ?><?php
                                if ($product['maxOrMinMarketPrice']['1']) {
                                    echo ' - ' . number_format($product['maxOrMinMarketPrice']['1'],2);
                                }
                                ?></span></b></div>
                    <div class="ml"><i class="linethr">门店价：￥<?php echo number_format($product['maxOrMinPrice']['0'],2); ?> - <?php echo number_format($product['maxOrMinPrice']['1'],2); ?></i></div>
                </div>
                <ul class="cl foodview_f tm15">
                    <li>
                        <a href="javascript:void(0);">
                            <b><?php echo $product['saleCount'] ? $product['saleCount'] : '0'; ?></b>
                            <u>月销量</u>
                        </a>
                    </li>
                    <li>
                        <a href="<?php echo Yii::app()->createUrl('site/product',array('id' => $_GET['id'],'#'=>'tabs')); ?>">
                            <b><?php echo $product['commontCount'] ? $product['commontCount'] : '0'; ?></b>
                            <u>累计评价</u>
                            <span class="starbg">
                                <span class="starcover" style="width:80%;"></span>
                            </span>
                        </a>
                    </li>
                </ul>
                <?php if($product['status'] == 1):?>
                <div class="inpout cl tm15 tb-sku">
                    <div class="inpl z" style="line-height: 30px;">分类</div>
                    <div class="inpr cl">
                        <ul class="skuselect cl">
                            <?php
                            for ($n = 0; $n < count($skuValuelist); $n++) {
                                ?>
                            <li<?php if(count($productSku)==1):?> class="selected"<?php endif;?>><a href="javascript:void(0);" skuvalueid="<?php echo implode(',', $skuValuelist[$n]['skuValueId']); ?>"><?php echo implode(' + ', $skuValuelist[$n]['skuValue']); ?></a><i>已选中</i></li>
                                <?php
                            }
                            ?>
                        </ul>
                    </div>
                </div>
                <div class="inpout cl tm10">
                    <div class="inpl z" style="line-height: 30px;">库存</div>
                    <div class="inpr cl now-quantity f_14" style="line-height: 30px;"><?php echo $allcount; ?></div>
                </div>
                <?php
                $this->pageTitle = $product['name'];
                $form = $this->beginWidget('CActiveForm', array(
                    'id' => 'product-form',
                    'enableClientValidation' => true,
                    'clientOptions' => array(
                        'validateOnSubmit' => true,
                    ),
                ));
                ?>
                <?php $sku_id = count($productSku)==1 ? $productSku['0']['id'] : '0';?>
                <?php echo $form->hiddenField($model, 'skuid', array('value' => $sku_id, 'class' => 'sku-id')); ?>
                <?php echo $form->hiddenField($model, 'sellerid', array('value' => $product['sellerId'])); ?>
                <div class="inpout cl tm15">
                    <div class="inpl z" style="line-height: 30px;">数量</div>
                    <div class="inpr cl">
                        <a href="javascript:void(0);" class="z less off"><span class="cmicons"></span></a>
                        <?php echo $form->textField($model, 'skuquantity', array('value' => $allcount > 0 ? 1 : 0, 'class' => 'z buy-num less_incr_amound')); ?>
                        <a href="javascript:void(0);" class="z incr"><span class="cmicons"></span></a>
                    </div>
                </div>
                <div class="inpout cl tm15">
                    <div class="inpr cl buybtn">
                        <?php $disablearr = array('31','33','39','40','46','49','50','51','52','53','54','55','56','57','58');?>
                        <?php if(in_array($product['sellerId'], $disablearr)): ?>
                        <?php echo CHtml::submitButton('暂时不能购买', array('class' => 'submit submit_gray z submit_wpd', 'name' => 'nowbuy','disabled'=>'disabled')); ?>
                        <?php echo CHTML::submitButton('暂时不能购买', array('class' => 'submit submit_gray z lm18 submit_wpd add-storelist','disabled'=>'disabled')); ?>
                        <?php else: ?>
                        <?php echo CHtml::submitButton('立即购买', array('class' => 'submit submit_orangelight z submit_wpd', 'name' => 'nowbuy')); ?>
                        <?php echo CHTML::ajaxSubmitButton('放进购物车', Yii::app()->baseUrl . '/ajax/account/?mod=addUserCart', array('dataType' => 'json', 'success' => 'js:function(json){if (json.content) { $(target).html(json.content);}if (json.callback) {eval(json.callback);}}'), array('class' => 'submit submit_blue z lm18 submit_wpd add-storelist')) ?>
                        <?php endif; ?>
                    </div>
                </div>
                <?php $this->endWidget(); ?>
                <?php else:?>
                <div class="product_close tm10">
                    商品已下架
                </div>
                <?php endif;?>
                <div class="inpout tm10">
                    <div class="inpr sitetips c_gray">灵动生活将保障您的购物资金及运费安全，查看保障须知。</div>
                </div>
            </div>
        </div>
        <div id="tabs">
            <ul class="productnav tm20 cl">
                <li><a href="#tab1" class="on">餐品详情</a></li><li><a href="#tab2">评价详情(<?php echo count($commont); ?>)</a></li>
            </ul>
            <div class="productview hide" id="tab1"><?php echo $product['productDesc']; ?></div>
            <div class="pjlist" id="tab2">
                <?php foreach ($commont as $key => $value) {?>
                    <ul>
                        <li>
                            <div class="avatar small z tm5">
                                <img src="<?php echo !$value['buyerImg'] ? Yii::app()->baseUrl.'/images/icon50.jpg' : $value['buyerImg'];?>" class="avatar-small" align="absmiddle"/>
                                    <div class="avatar_mask mask_small"></div>
                            </div>
                            <div class="commontuser">
                                <b class="z"><?php echo $value['userName'];?></b>
                                <span class="y c_gray"><?php echo $value['createTimeStr'];?></span>
                            </div>
<!--                            <div class="stars">
                                <span class="starbg">
                                    <span class="starcover" style="width:80%;"></span>
                                </span>
                            </div>-->
                            <div class="pjcontent"><?php echo $value['content']; ?></div>
                        </li>
                    </ul>
                <?php } ?>
            </div>
        </div>
    </div>
    <div class="area220 y">
        <div class="linehd">
            <span>他们还购买了</span>
        </div>
        <ul class="sidelist cl">
            <?php foreach ($row_samebuy as $key => $value) {
                ?>
                <li class="foodlayer">
                    <div class="food_img">
                        <a href="<?php echo Yii::app()->createUrl('site/product', array('id' => $value['productSkuId'])); ?>"><img src="<?php echo $value['productImg']['0']; ?>" align="absmiddle" style="width:100%;"/></a>
                    </div>
                    <div class="cl">
                        <span class="z"><a href="<?php echo Yii::app()->createUrl('site/product', array('id' => $value['productSkuId'])); ?>"><?php echo $value['name']; ?></a></span>
                        <span class="y c_b">￥<?php echo number_format($value['skuPrice'], 2); ?></span>
                    </div>
                </li>
            <?php }
            ?>
        </ul>
    </div>
</div>
<script>
    jQuery(document).ready(function($) {
        $(".ftoollist li").click(function() {
            $(this).siblings().removeClass("on");
            $(this).addClass("on");
            var preNumber = $(this).prevAll().size();
            $(".fimglist li").removeClass("onpre");
            $(".fimglist li:nth-child(" + preNumber + ")").addClass("onpre");
            var margin = 412;
            margin = margin * preNumber;
            margin = margin * -1;
            $(".fimglist").stop().animate({marginLeft: margin + "px"}, {duration: 500});
        });
        if (quantity <= 1) {
            $("a.incr").addClass('off');
            $("a.less").addClass('off');
            $("input.buy-num[type='text']").val(quantity);
        }
        $.ajax({
            type: "GET",
            url: "http://www.ldfood.cn:<?php echo Yii::app()->params['apiPortProduct']; ?>/ProductCenter/UpdateProductBehaver",
            data: "productId=<?php echo $product['id']; ?>&type=0&productSkuId=",
        });
    });
    $("#tabs").tabs();


       // ajaxGet('.store-list-box', 'addLiulan&id=<?php echo $product["id"]; ?>&name=<?php echo $product["name"]; ?>', 'ajax', 'html');
    <?php if (Yii::app()->user->isGuest): ?>
         <?php else: ?>
                //写入cookie浏览记录
                $(document).ready(function() {
                    var aptype = aptype ? aptype : 'append';
                $.ajax({
                    url: baseurl + '/ajax/ajax?mod=addLiulan&id=<?php echo $product["currentProductSkuId"]; ?>&name=<?php echo $product["name"]; ?>',
                    cache: false,
                    type: 'get',
                    async: false,
                    dataType: 'json',
                    success: function(json) {
                        if (json.content) {
                            $('.liulan-list-box').html(json.content);
                        }
                    }
                });
                });
         <?php endif; ?>

</script>